package com.yocard.yxyd.ui.activity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;
import com.yocard.yxyd.R;
import com.yocard.yxyd.adapter.BaseTabAdapter;
import com.yocard.yxyd.base.AppContext;
import com.yocard.yxyd.base.Constants;
import com.yocard.yxyd.http.HttpManager;
import com.yocard.yxyd.http.model.base.Response;
import com.yocard.yxyd.http.model.request.PushSettingRequest;
import com.yocard.yxyd.http.model.response.CertStatusBean;
import com.yocard.yxyd.http.model.response.PushSettingBean;
import com.yocard.yxyd.ui.activity.base.BaseActivity;
import com.yocard.yxyd.ui.contract.PushSettingContract;
import com.yocard.yxyd.ui.presenter.PushSettingPresenter;
import com.yocard.yxyd.utils.util.CacheDoubleStaticUtils;
import com.yocard.yxyd.utils.util.ConvertUtils;
import com.yocard.yxyd.utils.util.LogUtils;
import com.yocard.yxyd.utils.util.SPUtils;
import com.yocard.yxyd.utils.util.StringUtils;
import com.yocard.yxyd.utils.util.ToastUtils;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
import com.zaaach.citypicker.CityPicker;
import com.zaaach.citypicker.adapter.OnPickListener;
import com.zaaach.citypicker.db.DBManager;
import com.zaaach.citypicker.model.City;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created on 2019/6/4.
 * 订单推送设置
 */
public class PushSettingActivity extends BaseActivity<PushSettingPresenter> implements PushSettingContract.View {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.title_view)
    RelativeLayout titleView;
    @BindView(R.id.iv_selected)
    ImageView ivSelected;
    @BindView(R.id.ll_select_city)
    LinearLayout llSelectCity;
    @BindView(R.id.ll_select_time)
    LinearLayout llSelectTime;
    @BindView(R.id.rv_loan_amount)
    RecyclerView rvLoanAmount;
    @BindView(R.id.rv_loan_period)
    RecyclerView rvLoanPeriod;
    @BindView(R.id.rv_social_insurance)
    RecyclerView rvSocialInsurance;
    @BindView(R.id.rv_other_material)
    RecyclerView rvOtherMaterial;
    @BindView(R.id.tv_select_city)
    TextView tvSelectCity;
    @BindView(R.id.tv_select_time)
    TextView tvSelectTime;

    BaseTabAdapter<PushSettingBean.LoanRangeBean> loanAmountAdapter;
    BaseTabAdapter<PushSettingBean.LoanPeriodBean> loanPeriodAdapter;
    BaseTabAdapter<PushSettingBean.LoanInsuranceBean> socialInuranceAdapter;
    BaseTabAdapter<PushSettingBean.LoanHoldDataBean> materialAdapter;
    protected AMapLocationClient mLocationClient;

    String[] loanAmounts = {"1-3万", "3-5万", "5-10万", "10万以上"};
    String[] loanPeriods = {"1-3月", "3-6月", "6-12月", "12-18月", "18-24月", "24-36月"};
    String[] socialInurances = {"无社保", "连续缴纳＞6个月", "连续缴纳≤6个月"};
    String[] material = {"公积金", "微粒贷", "房产", "车产", "保险", "信用卡", "芝麻分"};

    //    String pushTime;
    static final String TIME_SPARATOR = "-";//起止时间显示分割符
    static final String SHARE_SEPARATOR = ",";//sharePerfernece字符数组,分隔符
    Gson gson = new Gson();

    @Override
    protected int getLayout() {
        return R.layout.act_puh_setting;
    }

    @Override
    protected void initEventAndData() {
        initTitle();
        showLoadingDialog();
        mPresenter.getPushParameters();
        initView();
        ImmersionBar.with(this)
                .fitsSystemWindows(true)
                .statusBarColorInt(Color.WHITE)
                .navigationBarColorInt(Color.BLACK)
                .autoDarkModeEnable(true, 0.2f)
                .init();
        initLocation();
    }

    private void initView() {
//        showLoadingDialog();
//        getFailDetail();

        HorizontalDividerItemDecoration horizontalBuild = new HorizontalDividerItemDecoration.Builder(mContext)
                .color(AppContext.getColor_(R.color.white))
                .size(ConvertUtils.dp2px(10))
                .build();

        loanAmountAdapter = new BaseTabAdapter<PushSettingBean.LoanRangeBean>() {
            @Override
            public String getTabText(PushSettingBean.LoanRangeBean data) {
                return data.getValue();
            }

            @Override
            public boolean tabSelected(PushSettingBean.LoanRangeBean data) {
                List<PushSettingBean.LoanRangeBean> selectedList = getSelectedList();
                boolean contain = false;
                for (PushSettingBean.LoanRangeBean data1 : selectedList) {
                    if (data1.getValue().equals(data.getValue())) {
                        contain = true;
                        break;
                    }
                }
                return contain;
            }
        };
        loanAmountAdapter.setOnTabSelectListener((int position, boolean selected) -> {
            List<PushSettingBean.LoanRangeBean> selectList = loanAmountAdapter.getSelectedList();
            PushSettingBean.LoanRangeBean bean = loanAmountAdapter.getItem(position);
            if (selected) {
                selectList.add(bean);
            } else {
                Iterator<PushSettingBean.LoanRangeBean> iterator = selectList.iterator();
                while (iterator.hasNext()) {
                    PushSettingBean.LoanRangeBean bean1 = iterator.next();
                    if (bean.getId() == bean1.getId()) {
                        iterator.remove();
                    }
                }
            }
            loanAmountAdapter.setSelectedList(selectList);
        });
//        loanAmountAdapter.setSelectedList(getSelectedList(Constants.LOAN_AMOUNT));
        rvLoanAmount.setLayoutManager(new GridLayoutManager(this, 4));
        rvLoanAmount.addItemDecoration(horizontalBuild);
        rvLoanAmount.setAdapter(loanAmountAdapter);

        loanPeriodAdapter = new BaseTabAdapter<PushSettingBean.LoanPeriodBean>() {
            @Override
            public String getTabText(PushSettingBean.LoanPeriodBean data) {
                return data.getValue();
            }

            @Override
            public boolean tabSelected(PushSettingBean.LoanPeriodBean data) {
                List<PushSettingBean.LoanPeriodBean> selectedList = getSelectedList();
                boolean contact = false;
                for (PushSettingBean.LoanPeriodBean data1 : selectedList) {
                    if (data1.getValue().equals(data.getValue())) {
                        contact = true;
                        break;
                    }
                }
                return contact;
            }
        };
        loanPeriodAdapter.setOnTabSelectListener((int position, boolean selected) -> {
            List<PushSettingBean.LoanPeriodBean> selectList = loanPeriodAdapter.getSelectedList();
            PushSettingBean.LoanPeriodBean bean = loanPeriodAdapter.getItem(position);
            if (selected) {
                selectList.add(bean);
            } else {
                Iterator<PushSettingBean.LoanPeriodBean> iterator = selectList.iterator();
                while (iterator.hasNext()) {
                    PushSettingBean.LoanPeriodBean bean1 = iterator.next();
                    if (bean.getId() == bean1.getId()) {
                        iterator.remove();
                    }
                }
            }
            loanPeriodAdapter.setSelectedList(selectList);
        });
//        loanPeriodAdapter.setSelectedList(getSelectedList(Constants.LOAN_PERIOD));
        rvLoanPeriod.setLayoutManager(new GridLayoutManager(this, 4));
        rvLoanPeriod.addItemDecoration(horizontalBuild);
        rvLoanPeriod.setAdapter(loanPeriodAdapter);

        socialInuranceAdapter = new BaseTabAdapter<PushSettingBean.LoanInsuranceBean>() {
            @Override
            public String getTabText(PushSettingBean.LoanInsuranceBean data) {
                return data.getValue();
            }

            @Override
            public boolean tabSelected(PushSettingBean.LoanInsuranceBean data) {
                List<PushSettingBean.LoanInsuranceBean> selectedList = getSelectedList();
                boolean contact = false;
                for (PushSettingBean.LoanInsuranceBean data1 : selectedList) {
                    if (data1.getValue().equals(data.getValue())) {
                        contact = true;
                        break;
                    }
                }
                return contact;
            }
        };
        socialInuranceAdapter.setOnTabSelectListener((int position, boolean selected) -> {
            List<PushSettingBean.LoanInsuranceBean> selectList = socialInuranceAdapter.getSelectedList();
            PushSettingBean.LoanInsuranceBean bean = socialInuranceAdapter.getItem(position);
            if (selected) {
                selectList.add(bean);
            } else {
                Iterator<PushSettingBean.LoanInsuranceBean> iterator = selectList.iterator();
                while (iterator.hasNext()) {
                    PushSettingBean.LoanInsuranceBean bean1 = iterator.next();
                    if (bean.getId() == bean1.getId()) {
                        iterator.remove();
                    }
                }
            }
            socialInuranceAdapter.setSelectedList(selectList);
        });
//        socialInuranceAdapter.setSelectedList(getSelectedList(Constants.SOCIAL_INSURACNCES));
        rvSocialInsurance.setLayoutManager(new GridLayoutManager(this, 3));
        rvSocialInsurance.addItemDecoration(horizontalBuild);
        rvSocialInsurance.setAdapter(socialInuranceAdapter);

        materialAdapter = new BaseTabAdapter<PushSettingBean.LoanHoldDataBean>() {
            @Override
            public String getTabText(PushSettingBean.LoanHoldDataBean data) {
                return data.getName();
            }

            @Override
            public boolean tabSelected(PushSettingBean.LoanHoldDataBean data) {
                List<PushSettingBean.LoanHoldDataBean> selectedList = getSelectedList();
                boolean contact = false;
                for (PushSettingBean.LoanHoldDataBean data1 : selectedList) {
                    if (data1.getName().equals(data.getName())) {
                        contact = true;
                        break;
                    }
                }
                return contact;
            }
        };
        materialAdapter.setOnTabSelectListener((int position, boolean selected) -> {
            List<PushSettingBean.LoanHoldDataBean> selectList = materialAdapter.getSelectedList();
            PushSettingBean.LoanHoldDataBean bean = materialAdapter.getItem(position);
            if (selected) {
                selectList.add(bean);
            } else {
                Iterator<PushSettingBean.LoanHoldDataBean> iterator = selectList.iterator();
                while (iterator.hasNext()) {
                    PushSettingBean.LoanHoldDataBean bean1 = iterator.next();
                    if (bean.getId() == bean1.getId()) {
                        iterator.remove();
                    }
                }
            }
            materialAdapter.setSelectedList(selectList);
        });
//        materialAdapter.setSelectedList(getSelectedList(Constants.OTHER_MATERIAL));
        rvOtherMaterial.setLayoutManager(new GridLayoutManager(this, 4));
        rvOtherMaterial.addItemDecoration(horizontalBuild);
        rvOtherMaterial.setAdapter(materialAdapter);
        tvSelectTime.setText("9:00-18:00");

//        ivSelected.setSelected(SPUtils.getInstance().getBoolean(Constants.PUSH_SUBSCRIBE, false));
//        pushTime = SPUtils.getInstance().getString(Constants.PUSH_TIME, "9:00-18:00");
//        setTime();
        tvSelectCity.setText(CacheDoubleStaticUtils.getString(Constants.KEY_CITY_NAME, "未定位"));
        PushSettingBean pushSettingBean = gson.fromJson(SPUtils.getInstance().getString(Constants.USER_PHONE) + SPUtils.getInstance().getString(Constants.PUSH_SETTING), PushSettingBean.class);
        updateSetting(pushSettingBean);
    }

    private List<String> getSelectedList(String share_key) {
        return new ArrayList<>(SPUtils.getInstance().getStringSet(share_key));
    }

    private void onTabSelected(BaseTabAdapter adapter, String share_key) {
//        List<String> stringList = adapter.getSelectedList();
//        saveSelectList(share_key, stringList);
    }

    private void saveSelectList(String share_key, List<String> stringList) {
        Set<String> stringSet = new HashSet<>(stringList);
        SPUtils.getInstance().put(share_key, stringSet);
    }

    @SuppressLint("CheckResult")
    private void getFailDetail() {
        HttpManager.getInstance().getCertStatus()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Response<CertStatusBean>>() {
                    @Override
                    public void accept(Response<CertStatusBean> beanResponse) throws Exception {
                    }
                });
    }

    private void initTitle() {
//        ImmersionBar.with(this).statusBarColor(R.color.white)
//                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText(R.string.push_subscribe);
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    public void onLocationInit(AMapLocationClient locationClient) {
        if (mLocationClient == null) {
            DBManager dbManager = new DBManager(mContext);
            mLocationClient = locationClient;
            mLocationClient.setLocationListener(new AMapLocationListener() {
                @Override
                public void onLocationChanged(AMapLocation location) {
                    String city = location.getCity();
                    SPUtils.getInstance().put(Constants.KEY_LONGITUDE, String.valueOf(location.getLongitude()));
                    SPUtils.getInstance().put(Constants.KEY_LATITUDE, String.valueOf(location.getLatitude()));

                    if (StringUtils.isEmpty(city)) {
                        ToastUtils.showLong("定位获取城市失败！");
                        return;
                    }

                    List<City> cities = dbManager.searchCity(city);
                    if (cities != null && cities.size() > 0) {
                        City seachCity = cities.get(0);


                        CacheDoubleStaticUtils.put(Constants.KEY_CITY_CODE, seachCity.getCode());
                        CacheDoubleStaticUtils.put(Constants.KEY_CITY_NAME, seachCity.getName());
                        tvSelectCity.setText(seachCity.getName());
                    }
                }
            });
        }
        mLocationClient.startLocation();
    }

    OnPickListener pickListener = new OnPickListener() {
        @Override
        public void onPick(int i, City city) {
            tvSelectCity.setText(city.getName());
            String currentCityCode = city.getCode();
            CacheDoubleStaticUtils.put(Constants.KEY_CITY_CODE, currentCityCode);
            CacheDoubleStaticUtils.put(Constants.KEY_CITY_NAME, city.getName());
        }

        @Override
        public void onLocate() {
            if (mLocationClient == null) {
                initLocation();
            } else {
                onLocationInit(mLocationClient);
            }
        }

        @Override
        public void onCancel() {

        }
    };

    public void initLocation() {
        AndPermission.with(AppContext.getContext())
                .runtime()
                .permission(Permission.ACCESS_FINE_LOCATION)
                .onGranted(permissions -> {
                    AMapLocationClient locationClient = new AMapLocationClient(AppContext.getContext());
                    AMapLocationClientOption mOption = new AMapLocationClientOption();
                    mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
                    mOption.setGpsFirst(false);
                    mOption.setNeedAddress(true);
                    mOption.setHttpTimeOut(10000);
                    mOption.setInterval(2000);
                    mOption.setOnceLocation(true);
                    locationClient.setLocationOption(mOption);
                    onLocationInit(locationClient);
                })
                .onDenied(permissions -> {
                    ToastUtils.showLong("请授予APP定位权限");
                })
                .start();
    }

    @OnClick({R.id.iv_back, R.id.iv_selected, R.id.ll_select_city, R.id.ll_select_time})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
            case R.id.iv_selected:
                view.setSelected(!view.isSelected());
//                SPUtils.getInstance().put(Constants.PUSH_SUBSCRIBE, view.isSelected());
                break;
            case R.id.ll_select_city:
                switchCity(pickListener, this);
                break;
            case R.id.ll_select_time:
                initNoLinkOptionsPicker();
                break;
        }
    }

    public void switchCity(OnPickListener listener, FragmentActivity activity) {
        CityPicker.from(activity)
                .enableAnimation(true)
                .setAnimationStyle(R.style.DefaultCityPickerAnimation)
                .setLocatedCity(null)
                .setOnPickListener(listener)
                .show();
    }

    private ArrayList<String> times = new ArrayList<>();

    private void initNoLinkOptionsPicker() {// 不联动的多级选项
        final List<String> firstData = new ArrayList<String>();
        final List<String> secondData = new ArrayList<String>();
        String pushTime = tvSelectTime.getText().toString();
        String[] times = pushTime.split(TIME_SPARATOR);
        int startIndex = 0;
        int endIndex = 0;
        for (int i = 0; i < 24; i++) {
            String str = String.valueOf(i);
//            if (i < 10) {
//                str = "0" + str;
//            }
            str += ":00";
            if (str.equals(times[0])) {
                startIndex = i;
            }
            if (str.equals(times[1])) {
                endIndex = i;
            }
            firstData.add(str);
            secondData.add(str);
        }
        OptionsPickerView pvNoLinkOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {

//                pushTime = firstData.get(options1) + ":00" + TIME_SPARATOR + secondData.get(options2) + ":00";
                setTime(firstData.get(options1) + ":00", secondData.get(options2) + ":00");
            }
        })
                .setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
                    @Override
                    public void onOptionsSelectChanged(int options1, int options2, int options3) {
                        String str = "options1: " + options1 + "\noptions2: " + options2;
                    }
                })
                .setTitleColor(getResources().getColor(R.color.color_4a4a4a))
                .setCancelColor(getResources().getColor(R.color.color_9f9f9f))
                .setDividerColor(getResources().getColor(R.color.color_dddddd))
                .setSubmitColor(getResources().getColor(R.color.color_04c15b))
                .setContentTextSize(16)
                .setTitleSize(16)
                .setSubCalSize(16)
                .setTitleText("选择推送时间")
                .build();
        pvNoLinkOptions.setNPicker(firstData, secondData);
        pvNoLinkOptions.setSelectOptions(startIndex, endIndex);

        pvNoLinkOptions.show();

    }

    private void setTime(String startTime, String endTime) {
        LogUtils.d("startTime = " + startTime + "  endTime = " + endTime);
        if (!TextUtils.isEmpty(startTime) && !TextUtils.isEmpty(endTime)) {
            startTime = startTime.substring(0, startTime.length() - 3);
            endTime = endTime.substring(0, endTime.length() - 3);
            tvSelectTime.setText(startTime + TIME_SPARATOR + endTime);
        }
//        String[] times = pushTime.split(TIME_SPARATOR);
//        SPUtils.getInstance().put(Constants.PUSH_TIME, pushTime);
    }

    private String getTime(Date date) {//可根据需要自行截取数据显示
        Log.d("getTime()", "choice date millis: " + date.getTime());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != mLocationClient) {
            mLocationClient.onDestroy();
        }

    }

    @Override
    public void onGetPushParameters(PushSettingBean pushSettingBean) {
        dismisDialog();
        SPUtils.getInstance().put(SPUtils.getInstance().getString(Constants.USER_PHONE) + Constants.PUSH_SETTING, gson.toJson(pushSettingBean));
        updateSetting(pushSettingBean);
    }

    private void updateSetting(PushSettingBean pushSettingBean) {
        if (pushSettingBean == null) return;
        String start = pushSettingBean.getStart_time();
        String end = pushSettingBean.getEnd_time();
//        pushTime = start + TIME_SPARATOR + end;
        setTime(start, end);
        ivSelected.setSelected(pushSettingBean.getStatus() == 1);
        if (!TextUtils.isEmpty(pushSettingBean.getCity_name())) {
            tvSelectCity.setText(pushSettingBean.getCity_name());
        }
        PushSettingBean.CusAttrBean cusAttrBean = pushSettingBean.getCusAttr();
        PushSettingBean.SubAttrBean subAttrBean = pushSettingBean.getSubAttr();
        loanPeriodAdapter.setSelectedList(cusAttrBean.getLoan_period());
        loanAmountAdapter.setSelectedList(cusAttrBean.getLoan_range());
        socialInuranceAdapter.setSelectedList(cusAttrBean.getLoan_insurance());
        materialAdapter.setSelectedList(cusAttrBean.getLoan_hold_data());
//        loanPeriodAdapter.setSelectedList(new HashSet<>(cusAttrBean.getLoan_period()));
//        loanAmountAdapter.setSelectedList(new HashSet<>(cusAttrBean.getLoan_range()));
//        socialInuranceAdapter.setSelectedList(new HashSet<>(cusAttrBean.getLoan_insurance()));
//        materialAdapter.setSelectedList(new HashSet<>(cusAttrBean.getLoan_hold_data()));
        loanPeriodAdapter.replaceDatas(subAttrBean.getLoan_period());
        loanAmountAdapter.replaceDatas(subAttrBean.getLoan_range());
        socialInuranceAdapter.replaceDatas(subAttrBean.getLoan_insurance());
        materialAdapter.replaceDatas(subAttrBean.getLoan_hold_data());
    }

    @Override
    public void onBackPressed() {
        int status = ivSelected.isSelected() ? 1 : 0;
        String city = tvSelectCity.getText().toString();
        String time = tvSelectTime.getText().toString();
        String start_time = "";
        String end_time = "";
        if (!TextUtils.isEmpty(time)) {
            String[] times = time.split(TIME_SPARATOR);
            if (times.length == 2) {
                start_time = times[0];
                end_time = times[1];
            }
        }
        List<Integer> loan_rang = new ArrayList<Integer>();
        for (PushSettingBean.LoanRangeBean bean : loanAmountAdapter.getSelectedList()) {
            loan_rang.add(bean.getId());
        }
        List<Integer> loan_period = new ArrayList<Integer>();
        for (PushSettingBean.LoanPeriodBean bean : loanPeriodAdapter.getSelectedList()) {
            loan_period.add(bean.getId());
        }
        List<Integer> loan_insurance = new ArrayList<Integer>();
        for (PushSettingBean.LoanInsuranceBean bean : socialInuranceAdapter.getSelectedList()) {
            loan_insurance.add(bean.getId());
        }
        List<Integer> loan_hold = new ArrayList<Integer>();
        for (PushSettingBean.LoanHoldDataBean bean : materialAdapter.getSelectedList()) {
            loan_hold.add(bean.getId());
        }
        PushSettingRequest pushSettingRequest = new PushSettingRequest();
        pushSettingRequest.setCity_name(city);
        pushSettingRequest.setStatus(status);
        pushSettingRequest.setStart_time(start_time);
        pushSettingRequest.setEnd_time(end_time);
        if (loan_hold.size() > 0) {
            pushSettingRequest.setLoan_hold_data(loan_hold);
        }
        if (loan_rang.size() > 0) {
            pushSettingRequest.setLoan_range(loan_rang);
        }
        if (loan_insurance.size() > 0) {
            pushSettingRequest.setLoan_insurance(loan_insurance);
        }
        if (loan_period.size() > 0) {
            pushSettingRequest.setLoan_period(loan_period);
        }
        mPresenter.savePushParameters(pushSettingRequest);
        super.onBackPressed();
    }
}
